﻿using System.Collections.Generic;
using CloudShot.Core.Interfaces;
using CloudShot.Utils;

namespace CloudShot.Settings
{
	internal sealed class SettingsRepository : ISettingsRepository
	{
		private readonly Dictionary<string, string> _settings = new Dictionary<string, string>();

		public Dictionary<string, string> Settings
		{
			get { return _settings; }
		}

		public void SetSetting<T>(string name, T value)
		{
			_settings[name] = GenericConverter.ConvertToString(value);
		}

		public T GetSetting<T>(string name)
		{
			string result;

			if (_settings.TryGetValue(name, out result))
			{
				return GenericConverter.ConvertFromString<T>(result); //(T)Convert.ChangeType(result, typeof(T));
			}

			return default(T);
		}
	}
}